package yxm.zyf.love.controller;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;

@RestController
public class HelloController {
//    @Resource
//    private RedisUtils redisUtils;
    
    @Value("${server.port}")
    Integer port;

    @GetMapping("/set")
    public String set(HttpSession session) {
        setConfig(session);
        return String.valueOf(port);
    }

    @GetMapping("/get")
    public String get(HttpSession session) {
        Config config = getConfig(session);
        return JSON.toJSONString(config) + "port:" + port;
    }
    
    private Config getConfig(HttpSession session){
        Config c=new Config();
        c.setAge((String)session.getAttribute("age"));
        c.setCar((String)session.getAttribute("car"));
        c.setPhone((String)session.getAttribute("phone"));
        c.setUserId((String)session.getAttribute("userId"));
        return c;
    }
    
    private void setConfig(HttpSession session){
        session.setAttribute("age", "22");
        session.setAttribute("car", "taxi");
        session.setAttribute("phone", "18997966144");
        session.setAttribute("userId", "2088622943096971");
    }
    
    //    @GetMapping("/getkey")
    //    public void get() {
    //        String value = redisUtils.get("room1");
    //        System.out.println(value);
    //    }

    @Scheduled(cron = "0/5 * * * * ? ")
    public void pppp(){
        System.out.println("定时任务");
    }

}

class Config{
    private String userId;
    
    private String car;
    
    private String phone;
    
    private String age;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getCar() {
        return car;
    }

    public void setCar(String car) {
        this.car = car;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
    
    
}